﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LotteryVote.Logic;
using LotteryVote.Entity;
using LotteryVote.Utility;
using LotteryVote.Logic.Web;
using LotteryVote.Logic.Application;
using LotteryVote.Controls;

namespace LotteryVote
{
    public partial class LottoSettingInfo : AuthorizePage
    {
        CompanyTypeFacade comTypeFacade = new CompanyTypeFacade();
        BetLimitFacade blGameBetLimit = new BetLimitFacade();
        GamePlayWayFacade gpwFacade = new GamePlayWayFacade();
        public IList<BetLimit> BetLimitList { get; private set; }
        public IList<GameBetLimit> GameBetLimitList { get; private set; }
        protected IList<GamePlayWay> GamePlayWayList;
        protected void Page_Load(object sender, EventArgs e)
        {
            InitParams();
        }

        void InitParams()
        {
            BetLimitList = blGameBetLimit.ListLimitByUser(CurrentUser.UserId);
            GameBetLimitList = blGameBetLimit.ListGameLimitByUser(CurrentUser.UserId);
            GamePlayWayList = LotterySystem.Current.GamePlayWay;
            LoadCommissionControl();
        }
        void LoadCommissionControl()
        {
            string control = CurrentUser.Role < SystemRole.Guest ? "AgentCommissionInfo" : "MemberCommissionInfo";
            string controlPath = string.Format("Controls/{0}.ascx", control);
            UserControl commControl = (UserControl)Page.LoadControl(controlPath);
            commControl.ID = "lv_comm";
            pl_comm.Controls.Add(commControl);
        }

        public GamePlayWay FindGamePlayWay(int gameId, int wayId)
        {
            return LotterySystem.Current.FindGamePlayWay(gameId, wayId);
        }
        public BetLimit FindBetLimit(int gameId)
        {
            return BetLimitList.Find(it => it.GameId == gameId);
        }
        public GameBetLimit FindGameLimit(int companyId, int gamePlayWayId)
        {
            return GameBetLimitList.Find(it => it.CompanyType == (CompanyType)companyId && it.GamePlayWayId == gamePlayWayId);
        }
    }
}